package indigo.collections 
{
	import flash.events.Event;

	/**
	 *  
	 * @author sebastiaan
	 * 
	 */	
	public class TreeNode
	{
		private var _parent:TreeNode;
		private var _data:*;
		private var _children:LinkedList;
		
		public function TreeNode(myData:*):void
		{
			data = myData;
			_children = new LinkedList();
		}
		
		
		public function get depth():uint
		{
			if (parent != null) {
				return parent.depth + 1;
			}
			return 0;
		}
		
		
		public function addChild(node:TreeNode):void
		{
			node.parent = this;
			_children.append(node);
		}
		
		
		public function removeChild(node:TreeNode):void
		{
			node.parent = null;
			
			_children.removeItem(node);
		}
		
		
		public function get numChildren():int
		{
			return _children.size;
		}
		
		/*
		public function iterator(type:String = null):IIterator
		{
			return new TreeIterator(this);
		}
		*/
		
		public function get children():LinkedList
		{
			return _children;
		}
		
		
		public function hasChildren():Boolean
		{
			return children.isEmpty();
		}
		
		
		public function get data():*
		{
			return _data;
		}
		
		
		public function set data(value:*):void
		{
			_data = value;
		}
		
		
		public function get parent():TreeNode
		{
			return _parent;
		}

		public function set parent(value:TreeNode):void
		{
			_parent = value;
		}
		
		
		public function dispose( event:Event = null ):void
		{
			children.dispose();
			data = null;
			parent = null;
		}
	}
}
